package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.system.SysPintuanType;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.ISysPintuanTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 拼团类型Controller
 *
 * @author zjw
 * @date 2023-08-03
 */
@RestController
@RequestMapping("/system/pintuan")
public class SysPintuanTypeController extends BaseController {
    @Autowired
    private ISysPintuanTypeService sysPintuanTypeService;

    /**
     * 查询拼团类型列表
     */
//    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public AjaxResult list(SysPintuanType sysPintuanType) {
        List<SysPintuanType> list = sysPintuanTypeService.selectSysPintuanTypeList(sysPintuanType);
        return success(list);
    }

    /**
     * 导出拼团类型列表
     */
//    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "拼团类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysPintuanType sysPintuanType) {
        List<SysPintuanType> list = sysPintuanTypeService.selectSysPintuanTypeList(sysPintuanType);
        ExcelUtil<SysPintuanType> util = new ExcelUtil<SysPintuanType>(SysPintuanType.class);
        util.exportExcel(response, list, "拼团类型数据");
    }

    /**
     * 获取拼团类型详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{pintuanId}")
    public AjaxResult getInfo(@PathVariable("pintuanId") Long pintuanId) {
        return success(sysPintuanTypeService.selectSysPintuanTypeByPintuanId(pintuanId));
    }

    /**
     * 新增拼团类型
     */
//    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "拼团类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPintuanType sysPintuanType) {
        sysPintuanType.setCreateBy(getUsername());
        sysPintuanType.setCreateTime(DateUtils.getNowDate());
        return toAjax(sysPintuanTypeService.insertSysPintuanType(sysPintuanType));
    }

    /**
     * 修改拼团类型
     */
//    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "拼团类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPintuanType sysPintuanType) {
        sysPintuanType.setUpdateBy(getUsername());
        sysPintuanType.setUpdateTime(DateUtils.getNowDate());
        return toAjax(sysPintuanTypeService.updateSysPintuanType(sysPintuanType));
    }

    /**
     * 删除拼团类型
     */
//    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "拼团类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{pintuanIds}")
    public AjaxResult remove(@PathVariable Long[] pintuanIds) {
        return toAjax(sysPintuanTypeService.deleteSysPintuanTypeByPintuanIds(pintuanIds));
    }
}
